package refactor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.standard.table.GroupFieldEnum;
import common.standard.table.PageEnum;
import org.springframework.beans.factory.annotation.Autowired;
import refactor.entity.Group;
import refactor.mapper.GroupMapper;
import refactor.service.IGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杨健
 * @since 2019-08-19
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService {
    private GroupMapper groupMapper;

    @Autowired
    public void setGroupMapper(GroupMapper groupMapper) {
        this.groupMapper = groupMapper;
    }

    /**
     * 分页查询显示区域
     *
     * @param regionId 用户的regionId
     * @param pageNum  当前页码
     * @return 分页包装对象
     */
    @Override
    public IPage<Group> pageList(Integer regionId, Integer pageNum) {
        Page<Group> groupPage = new Page<>(pageNum, PageEnum.PAGE_SIZE.getValue());

        QueryWrapper<Group> groupQueryWrapper = new QueryWrapper<>();
        groupQueryWrapper.eq(GroupFieldEnum.BELONG_TO.getFieldName(), regionId)
                .eq(GroupFieldEnum.IS_DELETED.getFieldName(), 0);

        return groupMapper.selectPage(groupPage, groupQueryWrapper);
    }
}
